import request from "@/utils/request";

export default {
  // 获取车辆列表
  getDriversList(searchModel) {
    return request({
      url: "/drivers/list",
      method: "get",
      params: {
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
        driverId: searchModel.driverId,
      },
    });
  },

  // 添加车辆信息
  addDrivers(drivers) {
    return request({
      url: "/drivers/add",
      method: "post",
      data: drivers,
    });
  },

  getDriversById(id) {
    return request({
      url: `/drivers/getById/${id}`,
      method: "get",
    });
  },

  deleteByid(id) {
    return request({
      url: `/drivers/${id}`,
      method: "delete",
    });
  },

  updateById(drivers) {
    return request({
      url: `/drivers/update`,
      method: "put",
      data: drivers,
    });
  },

  saveDrivers(drivers) {
    if (drivers.driverId !== null && drivers.driverId !== undefined) {
      return this.updateById(drivers);
    } else {
      return this.addDrivers(drivers);
    }
  },

  // 分配汽车
  assignCar(driverId, carId) {
    return request({
      url: `/drivers/assignCar/${driverId}/${carId}`,
      method: "put",
    });
  },
};
